package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.domain.SetmealDish;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Name SetmealController
 * @Author stella
 * @Date 2023-03-08 6:09 PM
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    /**
     * 根据菜品分类id查询套餐列表
     * @param categoryId
     * @param status
     * @return
     */
    @Cacheable(value = "setmeal",key = "#categoryId")
    @GetMapping("/list")
    public ResultInfo list(Long categoryId, Integer status){
        List<Setmeal> list = setmealService.findByCategoryId(categoryId,status);
        return ResultInfo.success(list);
    }

    /**
     * 套餐内菜品list
     * @param setmealId
     * @return
     */
    @GetMapping("/dish/{id}")
    public ResultInfo getDishes(@PathVariable(value = "id") Long setmealId){
        List<Dish> DishList = setmealService.getDishes(setmealId);
        return ResultInfo.success(DishList);
    }
}
